package bb.lanxing.activity.team;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.viewpager2.widget.ViewPager2;

import java.util.ArrayList;

import bb.lanxing.R;
import bb.lanxing.activity.base.BaseActivity;
import bb.lanxing.adapter.discover.BbsImageEditAdapter;

public class LargeImageActivity extends BaseActivity {
    private TextView titleView;
    private ViewPager2 viewPager;
    private BbsImageEditAdapter bbsImageEditAdapter = new BbsImageEditAdapter();
    private ArrayList<String> imageList = new ArrayList<>();
    private int currentImage = 0;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_image_edit);

        ImageView back = findViewById(R.id.back);
        back.setOnClickListener(v -> onBackPressed());

        titleView = findViewById(R.id.title);

        ImageView delete = findViewById(R.id.delete);
        delete.setVisibility(View.INVISIBLE);

        viewPager = findViewById(R.id.viewPager2);
        viewPager.registerOnPageChangeCallback(new ViewPager2.OnPageChangeCallback() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
                currentImage = position;
                titleView.setText((currentImage + 1) + "/" + imageList.size());
                super.onPageScrolled(position, positionOffset, positionOffsetPixels);
            }
        });
        viewPager.setAdapter(bbsImageEditAdapter);

        Intent intent = getIntent();
        imageList = intent.getStringArrayListExtra("images");
        bbsImageEditAdapter.updateData(imageList);

        currentImage = intent.getIntExtra("currentImage", 0);
        titleView.setText((currentImage + 1) + "/" + imageList.size());
        viewPager.setCurrentItem(currentImage, false);
    }
}